import http from 'axios'
import md5 from 'md5'
import store from 'store'
import moment from 'moment'
// import Vue from 'vue'
// import Router from 'vue-router'
import route from '@/router'
import {
  Base64
} from 'js-base64'

let config = window.config

// login
export function login () {
  let params = {
    'xxx1': 'GetToken',
    'xxx2': config.projectName,
    'xxx3': config.account,
    'xxx4': md5(config.password)
  }
  let loginStr = Base64.encode(JSON.stringify(params))
  return http.post('/v2/logon', loginStr).then(res => {
    let data = res.data
    store.set('token', data.token)
    store.set('projectName', data.project)
    store.set('user_id', data.user.ID)
  })
}

// get meeting by meeting room
export function getMeetingByRoom (roomid) {
  console.log(route.replace)
  let now = moment(new Date()).format('YYYY-MM-DD HH:mm:ss')
  let params = {
    'project_name': store.get('projectName'),
    'token': store.get('token'),
    'action': 'query',
    'room': roomid,
    'user_id': store.get('user_id'),
    'current_time': now,
    'type': 0
  }
  return http.post('/meeting', params)
}
